import java.util.Arrays;

class Solution {
    public static ListNode deleteDuplication(ListNode pHead) {
        if(pHead==null) {
            return null;
        }
        ListNode head=new ListNode(-1);
        head.next=pHead;
        int[] hash=new int[1001];
        Arrays.fill(hash,0);
        ListNode cur=pHead;
        while(cur!=null) {
            hash[cur.val]++;
            cur=cur.next;
        }
        int[] diff=new int[1000];
        int dex=0;
        for(int i=0;i<=1000;i++) {
            if(hash[i]!=0&&hash[i]!=1) {
                diff[dex++]=i;
            }
        }
        cur=pHead;
        ListNode pre=head;
        while(cur!=null) {
            boolean flag=false;
            for(int i=0;i<dex;i++) {
                if(cur.val==diff[i]) {
                    pre.next=cur.next;
                    cur=cur.next;
                    flag=true;
                    break;
                }
            }
            if(flag==false) {
                cur=cur.next;
                pre = pre.next;
            }
        }
        return head.next;
    }

    public static void main(String[] args) {
        ListNode pHead=new ListNode(1);
        ListNode pHead1=new ListNode(1);
        pHead.next=pHead1;
        deleteDuplication(pHead);
    }
}
public class newcoder2 {
}
